<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <script src="/js/layui/layui.all.js"></script>
    <!-- <script src="/admin/js/token.js"></script>-->
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div style="text-align: center;">
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="test-table-demoReload" placeholder="输入昵称或账号" autocomplete="off">
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin search" lay-submit lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
                    </button>
                </div>
            </div>
        </div>



        <div class="layui-card-body">
            <table class="layui-hide" id="t" lay-filter="t"></table>

        </div>

    </div>
</div>



</body>

<script type="text/html" id="tb">
    <div class="layui-container" style="margin-left:0px;">
        <a class="layui-btn layui-btn-xs" lay-event="add"><i class="layui-icon layui-icon-addition"></i>新增app用户</a>
    </div>
</script>

<script type="text/html" id="checkboxTpl">
    <input type="checkbox" name="status" value="{{d.id}}" title="启用" lay-filter="lockDemo" {{ d.status == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="caozuo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="chongzhi">重置密码</a>
</script>

<script>
    var $ = layui.$;
    var table = layui.table;
    var form = layui.form;
    table.render({
        elem: '#t',
        id: 'tt',
        toolbar: '#tb',
        url: '/appadmin/getAPP_Admin'
        ,
        cols: [
            [{
                field: 'id',
                title: '序号',
                width: '5%',
                type:'numbers',
                align: 'center'
            },
                {
                    field: 'username',
                    title: 'app用户账号',
                    width: '15%',
                    align: 'center'
                },

                {
                    field: 'phone',
                    title: '电话',
                    width: '12%',
                    align: 'center'
                },
                {
                    field: 'mail',
                    title: '邮箱',
                    width: '14%',
                    align: 'center'
                },
                {
                    field: 'shenyu_time',
                    title: '剩余时长（分钟）',
                    width: '14%',
                    align: 'center'
                },
                {
                    field: 'jiasu_time',
                    title: '使用加速时长（分钟）',
                    width: '15%',
                    align: 'center'
                },
                {
                    field: 'yuyan',
                    title: '语言',
                    width: '10%',
                    align: 'center',
                    templet:function(res){
                        switch(res.yuyan){
                            case "en":
                                   return  "英语"
                                break;
                            case "zh":
                                   return  "中文"
                                break;
                            case "lo":
                                   return  "老挝语"
                                break;
                            default:
                                return ""
                                break;
                        }
                    }
                },
                {fixed: 'right',field: 'status',width: '10%',align : 'center', title:'状态', templet: '#checkboxTpl', sort: true},
                {
                    title: '操作',
                    align: 'center',
                     width: '10%',
                    toolbar: '#caozuo',
                    fixed: 'right'
                }
            ]
        ],
        limit:40,
        page: true,
        done: (res, curr, count) => {
           // setTimeout(function () {
           //     table.reload('tt');
           // },60000)
        }
    });

    //监听用户状态
    form.on('checkbox(lockDemo)', function(obj){
        var id = this.value;
        if(obj.elem.checked){
            var status=1;
        }else{
            var status=0;
        }
        $.ajax({
            url:"/appadmin/updAPPAdminStatus"
            ,type:"GET"
            ,data:{id : id,status : status}
            ,contentType: 'application/json'
            ,success:function (data) {
                if(data.code==0){
                    layer.close(layer.index);
                    layer.msg('操作成功');
                    table.reload('tt');
                    // location.reload(true);
                }else if(data.code==1){
                    layer.msg(data.msg);
                }else{
                    layer.msg("拒绝访问");
                }
            }
            ,error:function () {
                console.log("ajax error");
            }
        });
    });

    //监听工具条
    table.on('tool(t)', function (obj) {
        var data = obj.data
        if (obj.event === 'detail') {
            layer.open({
                type: 2,
                area: ['100%', '100%'],
                content: 'editrole.html?adminId='+data.id, //这里content是一个普通的String
                end: function(){
                    location.reload();
                }
            });
        }else if(obj.event === 'chongzhi'){
            layer.confirm("确定重置密码吗?",{icon: 3, title:'提示'},function (index) {
                $.ajax({
                    type:"post",
                    url:"/appadmin/resetPassword",
                    data:{
                        id:data.id
                    },
                    dataType:"json",
                    success:function (res) {
                        if(res.code=200){
                            layer.msg("重置成功");
                        }else{
                            layer.msg("操作失败");
                        }
                    }
                })
            })
        }
    });

    table.on('toolbar(t)', function (obj) {
        var data = obj.data;
        // console.log(data);
        if (obj.event === 'add') {
            layer.open({
                type: 2,
                area: ['100%', '100%'],
                content: 'add_appuser.html', //这里content是一个普通的String
                end: function(){
                    location.reload();
                }
            });
        }
    });

    $('.test-table-operate-btn .layui-btn').on('click', function () {
        var type = $(this).data('type')
        active[type] ? active[type].call(this) : ''
    });

    $('.search').on('click',function () {
        var text = $('#test-table-demoReload').val();
        table.reload('tt',{
            where:{
                text:text
            },
            page:{
                curr:1
            }
        })
    })
</script>
</html>
